﻿using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using Autofac;
using Newtonsoft.Json.Linq;
using Pay.Core;
using Pay.DTO;
using Pay.DTO.hxdata;
using Pay.DTO.jwuct;
using Pay.DTO.rpay;
using Pay.DTO.rpay2;
using Pay.DTO.rpay4511;
using Pay.DTO.rpayout;
using Pay.DTO.rpayBh;
using Pay.IService;
using Pay.Service;
using Pay.TO;

namespace Pay.Api.Controllers {
	/// <summary>
	/// 快捷支付
	/// </summary>
	public partial class OpenController : BaseController {
		/// <summary>
		/// jwuct同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("jwuct_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<object> JwuctQuickNotify(string id, [FromBody]JObject model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("jwuct异步通知了:" + id);
			var _jwuctSign = new JwuctSign();
			if (_jwuctSign.VerifySign(model)) {
				var dto = model.ToObject<jwuct_notity>();
				log.Info("jwuct异步通知成功:" + dto.outTradeNo);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("jwuct－nosql获取失败:" + dto.outTradeNo);
					return new { resCode = "11", resDesc = "失败" };
				}
				var order = _iChargeService.Get(charge.merchant_no, dto.outTradeNo);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (dto.resultCode == "00" && dto.resCode == "00" && dto.status == "02") {
						var dt = dto.createTime.ToDateTime();
						result = _iChargeService.PaySuceess(obj, dto.orderNo, dt);
						if (result > 0) {
							var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
							var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
							if (notifyResult != "OK") {
								//创建通知消息对象
								_iPayNotifyService.Save(new pay_notify_dto {
									merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
									status = 2, create_time = DateTime.Now
								});
							}
							_iPayHtmlService.Remove(id);
						}
					} else {
						result = _iChargeService.PayFail(obj, dto.orderNo, dto.resDesc);
					}
				} else
					return new { resCode = "00", resDesc = "成功了" };
				//回执成功，通道不会再通知
				if (result > 0) {
					return new { resCode = "00", resDesc = "成功了" };
				}
				log.Info("jwuct-保存数据库订单失败:" + dto.outTradeNo);
				return new { resCode = "01", resDesc = "保存失败" }; ;
			}
			log.Info("jwuct-签名不正确:");
			return new { resCode = "01", resDesc = "签名不正确" };
		}

		/// <summary>
		/// hxdata同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("hxdata_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> HxDataQuickNotify(string id, [FromBody]hx_notify_model model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("hxdata异步通知了:" + id);
			var _hxdataSign = new HxDataSign();
			if (_hxdataSign.VerifySign(model)) {
				log.Info("hxdata异步通知成功:" + model.client_trans_id);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("hxdata－mongodb获取失败:" + model.client_trans_id);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, charge.order_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.resp_code == "PAY_SUCCESS") {
						var dt = DateTime.Now;
						result = _iChargeService.PaySuceess(obj, charge.order_no, dt);
						if (result > 0) {
							var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
							var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
							if (notifyResult != "OK") {
								//创建通知消息对象
								_iPayNotifyService.Save(new pay_notify_dto {
									merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
									status = 2, create_time = DateTime.Now
								});
							}
							_iPayHtmlService.Remove(id);
						}
					} else {
						result = _iChargeService.PayFail(obj, charge.order_no, model.resp_msg);
					}
				} else
					return "success";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "success";
				}
				log.Info("hxdata-保存数据库订单失败:" + model.client_trans_id);
				return "fail";
			}
			log.Info("hxdata-签名不正确:" + model.client_trans_id);
			return "签名不正确";
		}

		/// <summary>
		/// hxdata2同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("hxdata2_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> HxData2QuickNotify(string id, [FromBody]hx_notify_model model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("hxdata2异步通知了:" + id);
			var _hxdataSign = new Hx2Sign();
			if (_hxdataSign.VerifySign(model)) {
				log.Info("hxdata2异步通知成功:" + model.client_trans_id);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("hxdata2－mongodb获取失败:" + model.client_trans_id);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, charge.order_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.resp_code == "PAY_SUCCESS") {
						var dt = DateTime.Now;
						result = _iChargeService.PaySuceess(obj, charge.order_no, dt);
						if (result > 0) {
							var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
							var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
							if (notifyResult != "OK") {
								//创建通知消息对象
								_iPayNotifyService.Save(new pay_notify_dto {
									merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
									status = 2, create_time = DateTime.Now
								});
							}
							_iPayHtmlService.Remove(id);
						}
					} else {
						result = _iChargeService.PayFail(obj, charge.order_no, model.resp_msg);
					}
				} else
					return "success";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "success";
				}
				log.Info("hxdata2-保存数据库订单失败:" + model.client_trans_id);
				return "fail";
			}
			log.Info("hxdata2-签名不正确:" + model.client_trans_id);
			return "签名不正确";
		}

		/// <summary>
		/// rpay同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("rpay_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> RpayQuickNotify(string id, [FromBody]rpay_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpay异步通知了:" + id);
			var _rpaySign = new RpaySign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpay异步通知成功:" + model.out_trade_no);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("rpay－mongodb获取失败:" + model.out_trade_no);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, model.out_trade_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.state == "5") {
						var dt = DateTime.Now;
						result = _iChargeService.PaySuceess(obj, model.order_no, dt);
						if (result > 0) {
							var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
							var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
							if (notifyResult != "OK") {
								//创建通知消息对象
								_iPayNotifyService.Save(new pay_notify_dto {
									merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
									status = 2, create_time = DateTime.Now
								});
							}
							_iPayHtmlService.Remove(id);
						}
					} else {
						result = _iChargeService.PayFail(obj, model.order_no, "支付失败，状态" + model.state + "(订单状态0: 已下单 1:已受理 2: 请求预支付 3:请求失败 4:支付中 5: 支付成功 6:支付失败 7:超时关闭)");
					}
				} else
					return "SUCCESS";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "SUCCESS";
				}
				log.Info("rpay-保存数据库订单失败:" + model.out_trade_no);
				return "fail";
			}
			log.Info("rpay-签名不正确:" + model.out_trade_no);
			return "签名不正确";
		}

		/// <summary>
		/// rpay2－－同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("rpay2_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> RpayOutQuickNotify(string id, [FromBody]rpay2_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpay2异步通知了:" + id);
			var _rpaySign = new Rpay2Sign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpay2异步通知成功:" + model.out_order_no);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("rpay2－mongodb获取失败:" + model.out_order_no);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, model.out_order_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.status == "0000") {
						if (model.result_code == "0000") {
							var dt = DateTime.Now;
							result = _iChargeService.PaySuceess(obj, model.order_no, dt);
							if (result > 0) {
								var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
								var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
								if (notifyResult != "OK") {
									//创建通知消息对象
									_iPayNotifyService.Save(new pay_notify_dto {
										merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
										status = 2, create_time = DateTime.Now
									});
								}
								_iPayHtmlService.Remove(id);
							}
						} else {
							result = _iChargeService.PayFail(obj, model.order_no, model.result_msg);
						}
					} else {
						result = _iChargeService.PayFail(obj, model.order_no, model.message);
					}
				} else
					return "SUCCESS";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "SUCCESS";
				}
				log.Info("rpay2-保存数据库订单失败:" + model.out_order_no);
				return "fail";
			}
			log.Info("rpay2-签名不正确:" + model.out_order_no);
			return "签名不正确";
		}

		/// <summary>
		/// rpay代还－－同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("rpayout_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> Rpay2QuickNotify(string id, [FromBody]rpayout_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpayout-异步通知了:" + id);
			var _rpaySign = new RpayOutSign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpayout-异步通知成功:" + model.out_order_no);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("rpayout－mongodb获取失败:" + model.out_order_no);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, model.out_order_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.status == "0000") {
						if (model.result_code == "0000") {
							var dt = DateTime.Now;
							result = _iChargeService.PaySuceess(obj, model.order_no, dt);
							if (result > 0) {
								var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
								var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
								if (notifyResult != "OK") {
									//创建通知消息对象
									_iPayNotifyService.Save(new pay_notify_dto {
										merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
										status = 2, create_time = DateTime.Now
									});
								}
								_iPayHtmlService.Remove(id);
							}
						} else {
							result = _iChargeService.PayFail(obj, model.order_no, model.result_msg);
						}
					} else {
						result = _iChargeService.PayFail(obj, model.order_no, model.message);
					}
				} else
					return "SUCCESS";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "SUCCESS";
				}
				log.Info("rpayout-保存数据库订单失败:" + model.out_order_no);
				return "fail";
			}
			log.Info("rpayout-签名不正确:" + model.out_order_no);
			return "签名不正确";
		}

		/// <summary>
		/// rpay4511卡进件的状态通知
		/// </summary>
		/// <returns>The card notify.</returns>
		/// <param name="id">Identifier.</param>
		[Route("rpay4511_card_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public string Rpay4511CardNotify(string id, [FromBody]card_kj_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpay4511-卡进件异步通知了:" + id);
			var _rpaySign = new Rpay4511Sign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpay4511-卡进件异步通知成功:" + id);
				var obj = _iPayHtmlService.Get(id);
				card_kj_req card_kj = null;
				if (obj != null) {
					card_kj = obj.html.ToObject<card_kj_req>();
				} else {
					log.Info("rpay4511－mongodb获取失败:" + id);
					return "fail";
				}
				if (model.status == "0000" && model.result_code == "0000") {
					var charge = obj.charge.ToObject<charge_dto>();
					var oemer = _iMerchantService.Get(charge.merchant_no);
                    var oemer_registers = _iMerchantService.GetRegisters(oemer.id);
                    var register = oemer_registers.FirstOrDefault(c => c.pay_channel == PayChannel.RPAY4511);
					var card = register.cards.FirstOrDefault(c => c.account_no == card_kj.acctNo);
					AuthStatusEnum status = AuthStatusEnum.None;
					if (card != null) status = card.status;
					if (status != AuthStatusEnum.Auth) {
						if (model.activate_status == "2")
							status = AuthStatusEnum.Auth;
						if (card == null) {
							card = new card_status { account_no = card_kj.acctNo, status = status };
							register.cards.Add(card);
						} else {
							card.status = status;
						}
						var result = _iMerchantService.MerchantChannelRegister(register);
						if (result > 0) {
							return "SUCCESS";
						}
					}
					return "fail";
				}
			}
			return "签名不正确";
		}

		/// <summary>
		/// rpay4511－－同进同出通道回调通知
		/// </summary>
		/// <returns>The notify.</returns>
		/// <param name="model">Model.</param>
		[Route("rpay4511_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> Rpay4511QuickNotify(string id, [FromBody]rpay4511_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpay4511异步通知了:" + id);
			var _rpaySign = new Rpay4511Sign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpay4511异步通知成功:" + model.out_order_no);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("rpay4511－mongodb获取失败:" + model.out_order_no);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, model.out_order_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.status == "0000") {
						if (model.result_code == "0000" && model.order_status == "5") {
							var dt = DateTime.Now;
							result = _iChargeService.PaySuceess(obj, model.order_no, dt);
							if (result > 0) {
								var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
								var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
								if (notifyResult != "OK") {
									//创建通知消息对象
									_iPayNotifyService.Save(new pay_notify_dto {
										merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
										status = 2, create_time = DateTime.Now
									});
								}
								_iPayHtmlService.Remove(id);
							}
						} else {
							result = _iChargeService.PayFail(obj, model.order_no, model.result_msg);
						}
					} else {
						result = _iChargeService.PayFail(obj, model.order_no, model.message);
					}
				} else
					return "SUCCESS";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "SUCCESS";
				}
				log.Info("rpay4511-保存数据库订单失败:" + model.out_order_no);
				return "fail";
			}
			log.Info("rpay4511-签名不正确:" + model.out_order_no);
			return "签名不正确";
		}
		/// <summary>
		/// RpayBh --同进同出通道回调通知
		/// </summary>
		/// <returns>The bh quick notify.</returns>
		/// <param name="id">Identifier.</param>
		/// <param name="model">Model.</param>
		[Route("rpayBh_back_notify/{id}"), HttpPost, HttpGet, AllowAnonymous]
		public async Task<string> RpayBhQuickNotify(string id, [FromBody]rpayBh_notify model) {
			var log = IocHelper.Get<ILogHelper>("info");
			log.Info("rpayBh异步通知了:" + id);
			var _rpaySign = new RpayBhSign();
			if (_rpaySign.VerifySign(model)) {
				log.Info("rpayBh异步通知成功:" + model.out_trade_no);
				var result = 0;
				var obj = _iPayHtmlService.Get(id);
				charge_dto charge = null;
				if (obj != null) {
					charge = obj.charge.ToObject<charge_dto>();
				} else {
					log.Info("rpayBh－mongodb获取失败:" + model.out_trade_no);
					return "fail";
				}
				var order = _iChargeService.Get(charge.merchant_no, model.out_trade_no);
				//因为同进同出HTML的生成是用mongodb，所以要查数据库订单生成了没有，没有生成则调用返回参数处理
				if (order == null) {
					if (model.status == "0000") {
						if (model.result_code == "0000" && model.order_status == "5") {
							var dt = DateTime.Now;
							result = _iChargeService.PaySuceess(obj, model.order_no, dt);
							if (result > 0) {
								var _iPayService = _iocContext.ResolveKeyed<IPayService>(charge.pay_info.pay_channel);
								var notifyResult = await _iPayService.Notify(charge.merchant_no, charge.order_no);
								if (notifyResult != "OK") {
									//创建通知消息对象
									_iPayNotifyService.Save(new pay_notify_dto {
										merchant_no = charge.merchant_no, order_no = charge.order_no, pay_channel = charge.pay_info.pay_channel, type = 1,
										status = 2, create_time = DateTime.Now
									});
								}
								_iPayHtmlService.Remove(id);
							}
						} else {
							result = _iChargeService.PayFail(obj, model.order_no, model.result_msg);
						}
					} else {
						result = _iChargeService.PayFail(obj, model.order_no, model.message);
					}
				} else
					return "SUCCESS";
				//回执成功，通道不会再通知
				if (result > 0) {
					return "SUCCESS";
				}
				log.Info("rrpayBh-保存数据库订单失败:" + model.out_trade_no);
				return "fail";
			}
			log.Info("rpayBh-签名不正确:" + model.out_trade_no);
			return "签名不正确";
		}
		/// <summary>
		/// 商户进件异步通知
		/// </summary>
		/// <returns>The bh merchant register notify.</returns>
		/// <param name="model">Model.</param>
		[Route("rpayBh_reg_notify"), HttpGet, HttpPost, AllowAnonymous]
		public string RpayBhMerchantRegisterNotify([FromBody]rpayBh_reg_notify model) {
			//int result = 0;
			//var log = IocHelper.Get<ILogHelper>("info");
			//log.Info("rpayBh_reg异步通知了:" + model.ToJson());
			//var _rpaySign = new RpayBhSign();
			//if (_rpaySign.VerifySign(model)) {
			//	log.Info("rpayBh_reg异步通知成功:" + model.mch_id);
			//	if (model.status == "0000" && model.mch_status == "0") {
			//		result = _iMerchantService.SetMerchantRegister(model.mch_id);
			//	} else {
			//		log.Info("rpayBh_reg-进件失败:" + model.message);
			//		return "fail";
			//	}
			//}
			//if (result > 0)
			//	return "SUCCESS";
			//log.Info("rpayBh_reg-保存数据库进件失败:" + model.mch_id);
			//return "fail";
			return "SUCCESS";
		}
		/// <summary>
		/// 快捷支付
		/// </summary>
		/// <returns>The receive.</returns>
		/// <param name="model">Model.</param>
		protected async Task<quick_pay_result> QuickPay(quick_pay_model model) {
			if (model.type == 0) model.type = 1;
			if (string.IsNullOrEmpty(model.settle_type)) model.settle_type = "T0";
			if (string.IsNullOrEmpty(model.order_no))
				return ApiResultToJson.Json<quick_pay_result>("订单号不能为空");
			else {
				if (model.order_no.Length < 13)
					return ApiResultToJson.Json<quick_pay_result>("订单号最小14位");
				if (model.order_no.Length > 31)
					return ApiResultToJson.Json<quick_pay_result>("订单号最大长度30位");
			}
			if (string.IsNullOrEmpty(model.tran_amount))
				return ApiResultToJson.Json<quick_pay_result>("交易金额不能为空");
			if (string.IsNullOrEmpty(model.account_name))
				return ApiResultToJson.Json<quick_pay_result>("支付方姓名不能为空");
			if (string.IsNullOrEmpty(model.account_no))
				return ApiResultToJson.Json<quick_pay_result>("支付方银行卡号不能为空");
			if (string.IsNullOrEmpty(model.notify))
				return ApiResultToJson.Json<quick_pay_result>("支付成功后服务器回调该地址不能为空");
			if (model.pay_channel == PayChannel.None)
				return ApiResultToJson.Json<quick_pay_result>("通道不能为空");
			if (model.pay_channel == PayChannel.HF) {
				if (string.IsNullOrEmpty(model.card_type) || (!string.IsNullOrEmpty(model.card_type) && model.card_type != "DC" && model.card_type != "CC"))
					return ApiResultToJson.Json<quick_pay_result>("卡类型不能为空");
				if (string.IsNullOrEmpty(model.id_card))
					return ApiResultToJson.Json<quick_pay_result>("支付方身份证号不能为空");
			}

			//当前账户是否是黑名单

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPay(model);
		}

		/// <summary>
		/// 快捷支付鉴权成功后发短信
		/// </summary>
		/// <returns>The pay sendsms.</returns>
		/// <param name="model">Model.</param>
		protected async Task<ApiResultMessage> QuickPaySendsms(quick_sendsms_model model) {
			if (string.IsNullOrEmpty(model.order_no))
				return new ApiResultMessage(1001, "订单号不能为空");
			if (model.pay_channel == PayChannel.None)
				return new ApiResultMessage(1002, "通道不能为空");

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPaySendsms(model);
		}

		/// <summary>
		/// 快捷支付确认
		/// </summary>
		/// <param name="model"></param>
		/// <returns></returns>
		protected async Task<quick_pay_result> HfQuickPay(quick_sms_model model) {
			if (string.IsNullOrEmpty(model.sms_code))
				return ApiResultToJson.Json<quick_pay_result>("验证码不能为空");
			if (string.IsNullOrEmpty(model.order_no))
				return ApiResultToJson.Json<quick_pay_result>("订单号不能为空");
			if (model.pay_channel == PayChannel.None)
				return ApiResultToJson.Json<quick_pay_result>("通道不能为空");

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPay(model);
		}
		/// <summary>
		/// 升级快捷支付建权
		/// </summary>
		/// <param name="model"></param>
		/// <returns></returns>
		protected async Task<quick_pay_result> HFQuickUpPay(quick_pay_model model) {
			model.type = 2;
			return await QuickPay(model);
		}

		/// <summary>
		/// 快捷支付查询
		/// </summary>
		/// <returns>The pay query.</returns>
		/// <param name="model">Model.</param>
		protected async Task<pay_notity> QuickPayQuery(refund_model_query model) {
			if (string.IsNullOrEmpty(model.order_no) && string.IsNullOrEmpty(model.transaction_no))
				return ApiResultToJson.Json<pay_notity>("查询订单号或流水号不正确");
			if (model.pay_channel == PayChannel.None)
				return ApiResultToJson.Json<pay_notity>("通道不能为空");

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPayQuery(model);
		}

		/// <summary>
		/// 快捷支付退款
		/// </summary>
		/// <returns>The pay refund.</returns>
		/// <param name="model">Model.</param>
		protected async Task<refund_result> QuickPayRefund(refund_model model) {
			if (string.IsNullOrEmpty(model.tran_amount))
				return ApiResultToJson.Json<refund_result>("交易金额不能为空");
			if (string.IsNullOrEmpty(model.orig_order_no) && string.IsNullOrEmpty(model.transaction_no))
				return ApiResultToJson.Json<refund_result>("要退款的原订单号或流水号不正确");
			if (model.pay_channel == PayChannel.None)
				return ApiResultToJson.Json<refund_result>("通道不能为空");

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPayRefund(model);
		}

		/// <summary>
		/// 网关支付退款查询
		/// </summary>
		/// <returns>The pay refund.</returns>
		/// <param name="model">Model.</param>
		protected async Task<refund_result> QuickPayRefundQuery(refund_model_query model) {
			if (string.IsNullOrEmpty(model.order_no) && string.IsNullOrEmpty(model.transaction_no))
				return ApiResultToJson.Json<refund_result>("查询订单号或流水号不正确");
			if (model.pay_channel == PayChannel.None)
				return ApiResultToJson.Json<refund_result>("通道不能为空");

			var _iPayService = _iocContext.ResolveKeyed<IPayService>(model.pay_channel);
			return await _iPayService.QuickPayRefundQuery(model);
		}
	}
}
